package com.huilian.iotbox.admin.wap.service.impl;

import com.huilian.iotbox.admin.wap.service.UserRoleService;
import com.huilian.iotbox.data.dao.UserRoleDao;
import com.huilian.iotbox.data.po.UserRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author 少凡
 * @date 2020/3/1 21:51
 */
@Service
public class UserRoleServiceImpl implements UserRoleService {

    @Autowired
    private UserRoleDao userRoleDao;

    @Override
    public void add(UserRole userRole) {
        userRoleDao.insert(userRole);
    }

    @Override
    public Integer findByUserIdAndRoleId(UserRole userRole) {
        return userRoleDao.findByUserIdAndRoleId(userRole);
    }

    @Override
    public void delete(UserRole userRole) {
        userRoleDao.delete(userRole);
    }

    @Override
    public UserRole findOneUserRoleByUserId(Integer userId) {
        return userRoleDao.findOneUserRoleByUserId(userId);
    }

    @Override
    public UserRole findOneUserRoleByUserIdAndRoleType(Integer userId, Integer type) {
        return userRoleDao.findOneUserRoleByUserIdAndRoleType(userId, type);
    }

    @Override
    public int findSumNormalByRoleId(Integer roleId, Integer status) {
        Integer count = userRoleDao.findSumNormalByRoleId(roleId, status);
        if (StringUtils.isEmpty(count)){
            return 0;
        }
        return count;
    }
}
